﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SmartSpace.Core;
using SmartSapce.ServiceLocation;

namespace SmartSpace.WebApp._handlers._private
{
    /// <summary>
    /// Summary description for get_image
    /// </summary>
    public class get_image : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            Guid id = new Guid(context.Request.QueryString["id"]);
            ICoreService service = ServiceLocator.Get<ICoreService>();
            Image image = service.GetImage(id);
            context.Response.ContentType = "image/png";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BinaryWrite(image.Data);
        }

        #endregion
    }
}